package com.sz.common.base.exception;

import com.sz.common.base.logger.Logger;
import com.sz.common.base.utils.JsonUtils;
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
import org.springframework.util.ObjectUtils;

import java.lang.reflect.Method;

/**
 * Package: com.sz.common.base.exception<br>
 * Function: TODO: ADD FUNCTION <br>
 * Author: yanhong.xiao.<br>
 * Date: 2017-10-23 14:38:00.
 */
public class AsyncExceptionHandler implements AsyncUncaughtExceptionHandler {
    Logger logger = Logger.getLogger(this.getClass());

    @Override
    public void handleUncaughtException(Throwable ex, Method method, Object... objects) {
        StringBuilder params = new StringBuilder();
        if (!ObjectUtils.isEmpty(objects)) {
            for (Object o :
                    objects) {
                params.append(JsonUtils.toJSONString(o) + ";");
            }
        }
        logger.info("异步异常:->" +  " 方法所在类->" + method.getClass() + "方法名称->" + method.getName() + " 参数->" + "params:" + params.toString());
        logger.error("异步异常信息", ex);
        if (ex instanceof AsyncException) {
            AsyncException asyncException = (AsyncException) ex;
            logger.error("异步异常信息asyncException",asyncException);
        }

    }

}
